package Exercise;

import java.util.*;

/**
 * Description：找出 横纵坐标 没有都大于的点
 * Author: zhangc
 * Date：2017/8/22 23:09
 */
public class MaxPoint {

    static class Pair {
        int left;
        int right;

        public Pair(int left, int right) {
            this.left = left;
            this.right = right;
        }
    }

    public static void getMinPoint(List<Pair> pairs) {
        Collections.sort(pairs, Comparator.comparingInt(x -> x.left));
        Stack<Pair> stack = new Stack<>();
        int max = pairs.get(pairs.size() - 1).right;
        for (int i = pairs.size() - 1; i >= 0; i--) {
            if (pairs.get(i).right >= max) {
                stack.push(pairs.get(i));
                max = pairs.get(i).right;
            }
        }
        while (!stack.isEmpty()) {
            Pair pair = stack.pop();
            System.out.println(pair.left + " " + pair.right);
        }
    }

    public static void main(String[] args) {
        int[] left = {1, 5, 4, 7, 9};
        int[] right = {2, 3, 6, 5, 0};
        List<Pair> pairs = new ArrayList<>();
        for (int i = 0; i < left.length; i++) {
            Pair pair = new Pair(left[ i ], right[ i ]);
            pairs.add(pair);
        }
        getMinPoint(pairs);
    }

}
